package com.yl.auth.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yl.auth.entity.CuishouBean;
import com.yl.auth.service.CuishouService;
import com.yl.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 财务收支-催收管理
 * @belongsProject: ln-ylHouse
 * @belongsPackage: com.ln.auth.controller
 * @Date 2023/6/27 11:37
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@Api(tags = "财务收支-催收管理")
@RequestMapping("/admin/caiwushouzhi/cuishou")
@CrossOrigin
public class CuishouController {
    @Resource
    private CuishouService cuishouService;
//    @Resource
//    private CuishouMapper cuishouMapper;
//
//    @ApiOperation("分页+全查+条件")
//    @GetMapping("getAllPage/{page}/{limit}")
//    public Result getAllPage(@PathVariable Long page, @PathVariable Long limit, CuiShouVo cuiShouVo) {
//        IPage<CuishouBean> cs = new Page(page, limit);
//        QueryWrapper<CuishouBean> queryWrapper = new QueryWrapper<>();
//        String name = cuiShouVo.getName;
//        String state = cuiShouVo.getState;
//        if (!StringUtils.isEmpty(name)) {
//            queryWrapper.like("name", name);
//        }
//        if (!StringUtils.isEmpty(state)) {
//            queryWrapper.like("state", state);
//        }
//        IPage<CuishouBean> page1 = cuishouMapper.getAllPage(cs, queryWrapper);
//        return Result.ok(page1);
//    }


    @ApiOperation("分页条件查询")
    @GetMapping("/{page}/{limit}")
    public Result selepage(@PathVariable @ApiParam("当前页") Long page, @PathVariable @ApiParam("总条数") Long limit, @ApiParam("催收实体类") CuishouBean cuishouBean) {
        Page<CuishouBean> page1 = new Page<>(page, limit);
        IPage<CuishouBean> page2 = cuishouService.selectpage(page1, cuishouBean);
        return Result.ok(page2);
    }

    @ApiOperation("根据id查询")
    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Long id) {
        CuishouBean cuishouBean = cuishouService.getById(id);
        return Result.ok(cuishouBean);
    }

    @ApiOperation("根据id修改")
    @PostMapping("/updateById")
    private Result updateById(@RequestBody CuishouBean cuishouBean) {
        cuishouBean.setOfficialReceiptsPrice(cuishouBean.getReceivablePrice() - cuishouBean.getInsurancePrice());
        cuishouBean.setState("1");
        cuishouService.updateById(cuishouBean);
        return Result.ok();
    }

}
